import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { GisAttributeSearchUtils } from 'src/app/base/gis/search/gis.attribute.search';
import { GisPointSearchUtils } from 'src/app/base/gis/search/gis.point.search';

declare var form: any;

@Component({
  selector: 'attribute-find',
  templateUrl: './simple.component.html',
  styleUrls: ['./simple.component.scss']
})

// 简单属性查询
export class MapSimpleAttributeComponent implements OnInit {
  // 地图服务基础路径
  baseUrl = 'http://129.211.11.95:8066/geoserver/itfeer/wms';
  // 地图服务类型
  type = 'geoserver';
  // 图层列表
  nodes = [
    {
      title: '林地数据',
      key: '1000',
      children: [{
        title: '林地2018',
        key: 'zy_ldgx_2018_84',
        isLeaf: true
      }],
      disabled: true,
    },
  ];
  // 展开项
  expandKeys = ['1000'];
  // 查询条件属性
  attribute: any = {};
  // 选中图层名
  layerName = '';
  // 是否查询当前范围内
  inExtent = false;
  // 元数据
  medname = 'lgldzy';
  // 政区字典
  p_administrativeDic: any = null;
  // 地貌字典
  p_dimaoDic: any = null;
  // 属性查询工具服务
  searchService: any;
  // 属性查询查询参数
  paras = {
    type: '', baseUrl: '', layerName: '', inExtent: false,
    extent: {}, geometryField: ''
  };
  // 弹窗展示数据
  showFields: any;
  // 过滤条件
  filterWhere = { key: true, name: 'sheng' };


  constructor(private msg: NzMessageService) {
    this.searchService = new GisAttributeSearchUtils(this.msg);
    this.p_dimaoDic = new form.DictionaryService('DI_MAO');
    this.p_administrativeDic = new form.DictionaryService('p_administrative');
    // 设置弹窗数据
    form.FormDataService.getMetadata(this.medname, (e: any) => {
      this.showFields = new GisPointSearchUtils().filterFun(e, this.filterWhere);
    });
  }

  // 属性查询
  attributeSearch() {
    // 设置查询参数
    this.paras.type = this.type;
    this.paras.baseUrl = this.baseUrl;
    this.paras.layerName = this.layerName;
    this.paras.geometryField = 'geom';
    this.paras.inExtent = this.inExtent;
    this.paras.extent = this.inExtent === true ? form.ConfigService.map.getExtent() : {};

    // 开始查询
    this.searchService.attributeSearch(this.attribute, this.medname, this.paras);

  }

  // 清除属性
  clearAttribute() {
    this.attribute = {};
  }

  // 重新初始化属性查询
  reInitAttributeService() {
    this.searchService.reInitAttributeService(this.paras.type, this.searchService.option);
  }

  ngOnInit() {

  }
}
